/*
 * XMLDefaultHandler.java
 *
 * Created on 22 de Dezembro de 2004, 15:51
 */

package ceirinhashls.util;
//import javax.xml.parsers.*;
import ceirinhashls.DCHub;
import ceirinhashls.PublicHubList;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

/**
 *
 * @author  botelhodaniel
 */
public class XMLDefaultHandler extends DefaultHandler{
	private PublicHubList hublist;
	public XMLDefaultHandler(PublicHubList hublist){
		this.hublist=hublist;
	}
    public void startElement(String uri, String localName, String qName, Attributes attributes) 
    throws SAXException{
        if("Param".equals(qName)){
        	if(attributes.getValue("key").equals("USE_SESSION"))
                Settings.USE_SESSION = new Boolean(attributes.getValue("value")).booleanValue();
            else if(attributes.getValue("key").equals("FTP_SERVER_ADDRESS"))
                Settings.FTP_SERVER_ADDRESS= attributes.getValue("value");
            else if(attributes.getValue("key").equals("FTP_SERVER_USER"))
                Settings.FTP_SERVER_USER= attributes.getValue("value");
            else if(attributes.getValue("key").equals("FTP_SERVER_PASSWORD"))
                Settings.FTP_SERVER_PASSWORD= attributes.getValue("value");
            else if(attributes.getValue("key").equals("LOCAL_FILE_PATH"))
                Settings.LOCAL_FILE_PATH= attributes.getValue("value");
            else if(attributes.getValue("key").equals("REMOTE_FILE_PATH"))
                Settings.REMOTE_FILE_PATH= attributes.getValue("value");     
            else if(attributes.getValue("key").equals("OPEN_HUBLIST"))
                Settings.OPEN_HUBLIST= attributes.getValue("value");
            else if(attributes.getValue("key").equals("LOCAL_FILE"))
                Settings.LOCAL_FILE= new Boolean(attributes.getValue("value")).booleanValue();
            else if(attributes.getValue("key").equals("WEB_SERVER"))
                Settings.WEB_SERVER= new Boolean(attributes.getValue("value")).booleanValue();
            else if(attributes.getValue("key").equals("SCHEDULED"))
                Settings.SCHEDULED= new Boolean(attributes.getValue("value")).booleanValue();
            else if(attributes.getValue("key").equals("PING_ALL"))
                Settings.PING_ALL= new Boolean(attributes.getValue("value")).booleanValue();
            else if(attributes.getValue("key").equals("SCHEDULED_HOUR"))
                Settings.SCHEDULED_HOUR= attributes.getValue("value");
            else if(attributes.getValue("key").equals("SCHEDULED_MIN"))
                Settings.SCHEDULED_MIN= attributes.getValue("value");
        } else if ("Hub".equals(qName) && Settings.USE_SESSION) {
			try {
				this.hublist.addDCHub(new DCHub(attributes
						.getValue("netAddress"), attributes
						.getValue("lastUpdate"), attributes.getValue("name"),
						attributes.getValue("address"), attributes
								.getValue("description"), attributes
								.getValue("users"), attributes
								.getValue("shared"), attributes
								.getValue("country"), attributes
								.getValue("status"), attributes
								.getValue("minShare"), attributes
								.getValue("minSlots"), attributes
								.getValue("maxHubs"), attributes
								.getValue("maxUsers"), attributes
								.getValue("reliability"), attributes
								.getValue("rating"), attributes
								.getValue("port"), attributes
								.getValue("totalConnections"), attributes
								.getValue("faildConnections")));
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
    }
}
